package com.platform.service.impl;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.platform.annotation.SysLog;
import com.platform.common.ServerResponse;
import com.platform.dao.Psac0001Mapper;
import com.platform.dao.Psac0002Mapper;
import com.platform.pojo.Psac0001;
import com.platform.service.IPsacService;
import com.platform.util.NumberUtil;
import com.platform.util.PropertiesUtil;
import com.platform.util.StringUtil;
import com.xiaoleilu.hutool.http.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * 供应商基本信息服务层
 */
@Service("iPsacService")
public class PsacServiceImpl implements IPsacService {

    @Autowired
    private Psac0001Mapper psac0001Mapper;

    @Autowired
    private Psac0002Mapper psac0002Mapper;

    /**
     * 根据用户名查询企业基本信息
     * @param userName
     * @return
     */
    @SysLog("根据用户名查询投标人企业基本信息")
    public ServerResponse<Psac0001> selectByUserName(String userName){
        Psac0001 psac0001 = psac0001Mapper.selectByUserName(userName);
        if(null != psac0001){
            return ServerResponse.createBySuccess("查询成功",psac0001);
        }
        return ServerResponse.createByErrorMessage("查询失败");
    }

    /**
     * 根据条件查询投标人部分信息
     * @param paramMap
     * @return
     */
    @SysLog("根据条件查询投标人部分信息")
    public ServerResponse<PageInfo> selectByParam(Map paramMap){
        int pageNo = NumberUtil.safeToNumber(paramMap.get("pageNo"),1);
        int pageSize = NumberUtil.safeToNumber(paramMap.get("pageSize"),10);
        PageHelper.startPage(pageNo,pageSize,StringUtil.valueOfString(paramMap.get("order")));
        List<Map> resultList = psac0001Mapper.selectByParamMap(paramMap);
        PageInfo pageInfo = new PageInfo(resultList);
        pageInfo.setList(resultList);
        if(null != resultList && 0 < resultList.size()){
            return ServerResponse.createBySuccess("查询成功",pageInfo);
        }
        return ServerResponse.createByErrorMessage("查询失败");
    }

    /**
     * 根据ID查询投标人所有基础信息
     * @param id
     * @return
     */
    @SysLog("根据ID查询投标人所有基础信息")
    public ServerResponse<Map> selectById(Integer id){
        //查询出基本信息及开票信息（单个）
        Map resultMap = psac0001Mapper.selectById(id);
        //查询出银行账户信息
        List<Map> resutList =
        psac0002Mapper.selectByUserName(StringUtil.valueOfString(resultMap.get("supplier_code")));
        resultMap.put("bankList",resutList);
        return ServerResponse.createBySuccess("查询成功",resultMap);
    }

    /**
     * 根据id查询企业基本信息
     * @param id
     * @return
     */
    @SysLog("根据id查询投标人企业基本信息")
    public ServerResponse<Psac0001> selectOneById(Integer id){
        Psac0001 psac0001 = psac0001Mapper.selectByPrimaryKey(id);
        if(null != psac0001){
            return ServerResponse.createBySuccess("查询成功",psac0001);
        }
        return ServerResponse.createByErrorMessage("查询失败");
    }

    /**
     * 新增
     * @param psac0001
     * @return
     */
    @SysLog("新增投标人企业基本信息")
    public ServerResponse<String> insert(Psac0001 psac0001){
        if(psac0001Mapper.insert(psac0001) > 0){
            return ServerResponse.createBySuccessMessage("操作成功");
        }
        return ServerResponse.createByErrorMessage("操作失败");
    }

    /**
     * 更新
     * @param psac0001
     * @return
     */
    @SysLog("更新投标人企业基本信息")
    public ServerResponse<String> update(Psac0001 psac0001){
        if(psac0001Mapper.updateByPrimaryKeySelective(psac0001) > 0){
            return ServerResponse.createBySuccessMessage("操作成功");
        }
        return ServerResponse.createByErrorMessage("操作失败");
    }

    /**
     * 根据用户名查询投标人具体信息
     * @param userName
     * @return
     */
    public ServerResponse<Map> selectByUName(String userName){
        return null;
    }

}
